import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author zyj
 * @date 2022年06月10日 14:46
 */
public class newScheduledThreadPoolDemo延迟执行 {
    public static void main(String[] args) {
        ScheduledExecutorService service  = Executors.newScheduledThreadPool(5);

        for (int i = 0; i < 5; i++) {
            final int index = i;
            //延迟3秒执行
            service.schedule(new Runnable() {
                @Override
                public void run() {
                    System.out.println("第" + index + "个线程" + Thread.currentThread().getName());
                }
            },3, TimeUnit.SECONDS);



        }
        service.shutdown();

    }
}
